package com.sicaolong.partterndesign._03builder;

public class Person {
    private String name;
    private int age;
    private String email;
    private String phone;
    private Address address;

    Person(String name, int age, String email, String phone, Address address) {
        this.name = name;
        this.age = age;
        this.email = email;
        this.phone = phone;
        this.address = address;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Person{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", email='").append(email).append('\'');
        sb.append(", phone='").append(phone).append('\'');
        sb.append(", address=").append(address);
        sb.append('}');
        return sb.toString();
    }

    public static PersonBuilder builder() {
        return new PersonBuilder();
    }

    public static class PersonBuilder {
        private String name;
        private int age;
        private String email;
        private String phone;
        private Address address;

        PersonBuilder() {
        }

        public PersonBuilder setName(String name) {
            this.name = name;
            return this;
        }

        public PersonBuilder setAge(int age) {
            this.age = age;
            return this;
        }

        public PersonBuilder setEmail(String email) {
            this.email = email;
            return this;

        }

        public PersonBuilder setPhone(String phone) {
            this.phone = phone;
            return this;

        }

        public PersonBuilder setAddress(Address address) {
            this.address = address;
            return this;
        }

        public Person build() {
            return new Person(this.name, this.age, this.email, this.phone, this.address);
        }
    }
}
